#! /usr/bin/python  
# -*- coding: utf-8-*-

"""
此文件读取vocabulary.txt文件，然后依次从dict.cn获取解释文件
有任何问题，请联系baizhenxuan@gmail.com
"""
from  urllib import *
import os,sys 
err=open("errorfile.txt","w+");
def getword(word):
    url="http://dict.cn/mini.php?q="+word;
    if(os.path.exists(word)):
        return;
    f=urlopen(url);
    s=f.read();
    print word
    open(word,"w+").write(s);
if __name__=="__main__":
    f=open("vocabulary.txt","r");
    l=f.readlines();
    print len(l);
    for i in l:
        try:
            getword(i.strip());
        except:
            err.write("error occur :"+i.strip());
